#region Copyright RenGuiYou. All rights reserved.

//=====================================================
// PandoraFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================

#endregion

using UnityEngine;

namespace Pandora.Console
{
    public class ScreenInfoWindow : ScrollWindowBase
    {
        protected override void OnDrawScrollableWindow()
        {
            GUILayout.Label("<b>屏幕信息</b>");
            GUILayout.BeginVertical("box");
            {
                DrawItem("当前分辨率", GetResolutionString(Screen.currentResolution));
                //                DrawItem("Screen Width", string.Format("{0} px / {1} in / {2} cm", Screen.width.ToString(), Utility.Converter.GetInchesFromPixels(Screen.width).ToString("F2"), Utility.Converter.GetCentimetersFromPixels(Screen.width).ToString("F2")));
                //                DrawItem("Screen Height", string.Format("{0} px / {1} in / {2} cm", Screen.height.ToString(), Utility.Converter.GetInchesFromPixels(Screen.height).ToString("F2"), Utility.Converter.GetCentimetersFromPixels(Screen.height).ToString("F2")));
                DrawItem("屏幕DPI", Screen.dpi.ToString("F2"));
                DrawItem("屏幕方向", Screen.orientation.ToString());
                DrawItem("是否全屏", Screen.fullScreen.ToString());
                DrawItem("休眠超时", GetSleepTimeoutDescription(Screen.sleepTimeout));
                DrawItem("显示光标", Cursor.visible.ToString());
                DrawItem("锁定光标", Cursor.lockState.ToString());
                DrawItem("屏幕左转", Screen.autorotateToLandscapeLeft.ToString());
                DrawItem("屏幕右转", Screen.autorotateToLandscapeRight.ToString());
                DrawItem("自动纵向", Screen.autorotateToPortrait.ToString());
                DrawItem("自动纵向(反)", Screen.autorotateToPortraitUpsideDown.ToString());
                DrawItem("支持分辨率", GetResolutionsString(Screen.resolutions));
            }
            GUILayout.EndVertical();
        }

        private string GetSleepTimeoutDescription(int sleepTimeout)
        {
            if (sleepTimeout == SleepTimeout.NeverSleep)
            {
                return "永不休眠";
            }

            if (sleepTimeout == SleepTimeout.SystemSetting)
            {
                return "系统设置";
            }

            return sleepTimeout.ToString();
        }

        private string GetResolutionString(Resolution resolution)
        {
            return string.Format("{0} x {1} @ {2}Hz", resolution.width.ToString(), resolution.height.ToString(), resolution.refreshRate.ToString());
        }

        private string GetResolutionsString(Resolution[] resolutions)
        {
            string[] resolutionStrings = new string[resolutions.Length];
            for (int i = 0; i < resolutions.Length; i++)
            {
                resolutionStrings[i] = GetResolutionString(resolutions[i]);
            }

            return string.Join("; ", resolutionStrings);
        }
    }
}